From a62093f8fa9a206056e9bb59e69bae0e259d78ae Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Wed, 27 Jan 2021 12:01:41 -0700 Subject: [PATCH] Update standards to c++17, Qt >= 5.12, MSVC >= 2017 (#670) * raise minimum standards to c++17, Qt 5.12, MSVC 2017. * avoid std::optional::value which didn't work until macOS 10.14. * avoid std::optional::value which didn't work until macOS 10.14. * update runner for codeql so we have Qt >= 5.12 * try harder to get codeql working with newer Qt. * use c++17 fallthrough attribute. * use c++17 'if constexpr' as suggested by resharper. * catch mkicondoc up with c++17 --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/ubuntu.yml | 2 +- .github/workflows/windows.yml | 7 ------ CMakeLists.txt | 5 ++-- GPSBabel.pro | 5 ++-- defs.h | 34 ++++++++------------------- delgpl.cc | 2 +- dmtlog.cc | 2 +- g7towin.cc | 2 +- garmin_fit.cc | 12 ---------- garmin_fit.h | 5 ---- gpx.h | 5 ---- gui/CMakeLists.txt | 4 ++-- gui/app.pro | 1 + gui/main.cc | 6 +++-- height.cc | 9 ------- igc.cc | 30 +++++++++++------------ igo8.cc | 6 ++--- interpolate.cc | 12 +++++----- interpolate.h | 3 ++- kml.cc | 2 +- lowranceusr.cc | 27 --------------------- lowranceusr.h | 10 -------- main.cc | 10 ++++++-- mkicondoc/mkicondoc.pro | 2 +- route.cc | 2 +- skytraq.cc | 4 ++-- src/core/{ => deprecated}/optional.h | 0 util.cc | 4 ++-- xcsv.cc | 6 ++--- xcsv.h | 10 ++++---- 31 files changed, 75 insertions(+), 156 deletions(-) rename src/core/{ => deprecated}/optional.h (100%) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2822167bd..e71c1e0c1 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: analyze: name: Analyze runs-on: ubuntu-latest - container: tsteven4/gpsbabel_build_environment + container: tsteven4/gpsbabel_build_environment_focal strategy: fail-fast: false diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 08440e47a..3b2edc22d 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -14,7 +14,7 @@ jobs: name: basic Build runs-on: ubuntu-latest container: - image: gpsbabel-docker.jfrog.io/tsteven4/gpsbabel_build_environment + image: gpsbabel-docker.jfrog.io/tsteven4/gpsbabel_build_environment_focal env: LC_ALL: 'C.UTF-8' diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 446e62a51..59c59811b 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -43,13 +43,6 @@ jobs: VCVERSION: '14.16' FLOW: 'nmake' RELEASE: false - - QT_VERSION: '5.12.10' - ARCH: 'amd64' - HOST_ARCH: 'x86' - COMPILER: 'msvc2017_64' - VCVERSION: '14.0' - FLOW: 'nmake' - RELEASE: false - QT_VERSION: '5.12.10' ARCH: 'x86' HOST_ARCH: 'x86' diff --git a/CMakeLists.txt b/CMakeLists.txt index 3654531e2..0f0b3dbfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.5.1) project(gpsbabel LANGUAGES C CXX) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) # Find includes in corresponding build directories @@ -15,7 +15,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) # Find the Qt5Core library find_package(Qt5 COMPONENTS Core REQUIRED) -if(${Qt5Core_VERSION} VERSION_LESS 5.9) +if(${Qt5Core_VERSION} VERSION_LESS 5.12) message(FATAL_ERROR "Qt version ${Qt5Core_VERSION} found, but version 5.9 or newer is required.") else() message(STATUS "Using Qt5 version ${Qt5Core_VERSION}") @@ -179,7 +179,6 @@ set(HEADERS src/core/datetime.h src/core/file.h src/core/logging.h - src/core/optional.h src/core/textstream.h src/core/usasciicodec.h src/core/xmlstreamwriter.h diff --git a/GPSBabel.pro b/GPSBabel.pro index f6ef73746..f9ed6ecea 100644 --- a/GPSBabel.pro +++ b/GPSBabel.pro @@ -1,6 +1,6 @@ # Enforce minimum Qt version. # versionAtLeast() was introduced in Qt 5.10, so we can't count on it being available. -MIN_QT_VERSION = 5.9 # major[.minor[.patch]] +MIN_QT_VERSION = 5.12 # major[.minor[.patch]] MIN_QT_VERSION_COMPONENTS = $$split(MIN_QT_VERSION, .) MIN_QT_VERSION_MAJOR = $$member(MIN_QT_VERSION_COMPONENTS, 0) MIN_QT_VERSION_MINOR = $$member(MIN_QT_VERSION_COMPONENTS, 1) @@ -20,7 +20,7 @@ VERSION = 1.7.0 CONFIG += console CONFIG -= app_bundle -CONFIG += c++14 +CONFIG += c++17 CONFIG += link_pkgconfig TEMPLATE = app @@ -182,7 +182,6 @@ HEADERS = \ src/core/datetime.h \ src/core/file.h \ src/core/logging.h \ - src/core/optional.h \ src/core/textstream.h \ src/core/usasciicodec.h \ src/core/xmlstreamwriter.h \ diff --git a/defs.h b/defs.h index e35dc2625..a6617f0f5 100644 --- a/defs.h +++ b/defs.h @@ -26,6 +26,7 @@ #include // for int32_t, uint32_t #include // for NULL, fprintf, FILE, stdout #include // for time_t +#include // for optional #include // for move #if HAVE_CONFIG_H @@ -52,7 +53,6 @@ #include "gbfile.h" // doesn't really belong here, but is missing elsewhere. #include "session.h" // for session_t #include "src/core/datetime.h" // for DateTime -#include "src/core/optional.h" // for optional #define CSTR(qstr) ((qstr).toUtf8().constData()) @@ -676,17 +676,17 @@ waypt_disp_all(T cb) */ struct computed_trkdata { double distance_meters{0.0}; - gpsbabel_optional::optional max_alt; /* Meters */ - gpsbabel_optional::optional min_alt; /* Meters */ - gpsbabel_optional::optional max_spd; /* Meters/sec */ - gpsbabel_optional::optional min_spd; /* Meters/sec */ - gpsbabel_optional::optional avg_hrt; /* Avg Heartrate */ - gpsbabel_optional::optional avg_cad; /* Avg Cadence */ + std::optional max_alt; /* Meters */ + std::optional min_alt; /* Meters */ + std::optional max_spd; /* Meters/sec */ + std::optional min_spd; /* Meters/sec */ + std::optional avg_hrt; /* Avg Heartrate */ + std::optional avg_cad; /* Avg Cadence */ gpsbabel::DateTime start; /* Min time */ gpsbabel::DateTime end; /* Max time */ - gpsbabel_optional::optional min_hrt; /* Min Heartrate */ - gpsbabel_optional::optional max_hrt; /* Max Heartrate */ - gpsbabel_optional::optional max_cad; /* Max Cadence */ + std::optional min_hrt; /* Min Heartrate */ + std::optional max_hrt; /* Max Heartrate */ + std::optional max_cad; /* Max Cadence */ }; class route_head @@ -974,20 +974,6 @@ void setshort_defname(short_handle, const char* s); #define ARG_NOMINMAX nullptr, nullptr struct arglist_t { - /* MSVC 2015 generates C2440, C2664 errors without some help. */ -#if defined(_MSC_VER) && (_MSC_VER < 1910) /* MSVC 2015 or earlier */ - arglist_t() = default; - arglist_t(const char* astr, char** aval, const char* hstr, const char* dval, - const uint32_t atyp, const char* minv, const char* maxv, char* avp) : - argstring(astr), - argval(aval), - helpstring(hstr), - defaultvalue(dval), - argtype(atyp), - minvalue(minv), - maxvalue(maxv), - argvalptr(avp) {} -#endif const char* argstring{nullptr}; char** argval{nullptr}; const char* helpstring{nullptr}; diff --git a/delgpl.cc b/delgpl.cc index 4b911793c..c368f9a92 100644 --- a/delgpl.cc +++ b/delgpl.cc @@ -42,7 +42,7 @@ static void gpl_rd_init(const QString& fname) { gplfile_in = gbfopen_le(fname, "rb", MYNAME); - if (sizeof(gpl_point_t) != 56) { + if constexpr (sizeof(gpl_point_t) != 56) { fatal(MYNAME ": gpl_point is %zu instead of 56.\n", sizeof(gpl_point_t)); } diff --git a/dmtlog.cc b/dmtlog.cc index 07fe094ae..3b5597598 100644 --- a/dmtlog.cc +++ b/dmtlog.cc @@ -585,7 +585,7 @@ inflate_buff(const char* buff, const size_t size, char** out_buff) switch (res) { case Z_NEED_DICT: res = Z_DATA_ERROR; - /* fallthrough */ + [[fallthrough]]; case Z_DATA_ERROR: case Z_MEM_ERROR: (void)inflateEnd(&strm); diff --git a/g7towin.cc b/g7towin.cc index 4efcc98db..108ebad7e 100644 --- a/g7towin.cc +++ b/g7towin.cc @@ -188,7 +188,7 @@ parse_line(char* buff, int index, const char* delimiter, Waypoint* wpt) if (strcmp(cin, "1.0e25") == 0) { break; } - /* fallthrough */ + [[fallthrough]]; case WPT_cD_OFS + 1: case WPT_cB_OFS + 6: WAYPT_SET(wpt, temperature, atof(cin)); diff --git a/garmin_fit.cc b/garmin_fit.cc index 4208fbcb0..29ae7d456 100644 --- a/garmin_fit.cc +++ b/garmin_fit.cc @@ -47,18 +47,6 @@ #define MYNAME "fit" -// Until c++17 we have to define odr-used constexpr static data members at namespace scope. -#if __cplusplus < 201703L -constexpr int GarminFitFormat::kTypeEnum; -constexpr int GarminFitFormat::kTypeUint8; -constexpr int GarminFitFormat::kTypeString; -constexpr int GarminFitFormat::kTypeUint16; -constexpr int GarminFitFormat::kTypeSint32; -constexpr int GarminFitFormat::kTypeUint32; -constexpr int GarminFitFormat::kCoursePointTypeLeft; -constexpr int GarminFitFormat::kCoursePointTypeRight; -#endif - /******************************************************************************* * %%% global callbacks called by gpsbabel main process %%% * *******************************************************************************/ diff --git a/garmin_fit.h b/garmin_fit.h index 4cbd8d8cb..6fc6ab69b 100644 --- a/garmin_fit.h +++ b/garmin_fit.h @@ -84,11 +84,6 @@ private: /* Types */ struct fit_field_t { - /* MSVC 2015 generates C2664 errors without some help. */ -#if defined(_MSC_VER) && (_MSC_VER < 1910) /* MSVC 2015 or earlier */ - fit_field_t() = default; - fit_field_t(int i, int s, int t) : id(i), size(s), type(t) {} -#endif int id {}; int size{}; int type{}; diff --git a/gpx.h b/gpx.h index 4b9bc1a93..4247afe53 100644 --- a/gpx.h +++ b/gpx.h @@ -182,11 +182,6 @@ private: }; struct tag_mapping { -#if defined(_MSC_VER) && (_MSC_VER < 1910) /* MSVC 2015 or earlier */ - /* avoid MSVC 2015 C2664 errors. */ - tag_mapping() = default; - tag_mapping(tag_type t, bool p) : type(t),passthrough(p) {} -#endif tag_type type{tt_unknown}; /* enum from above for this tag */ bool passthrough{true}; /* true if we don't generate this */ }; diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 9fd4ee063..99b157e44 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.5.1) project(gpsbabelfe LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) # Find includes in corresponding build directories @@ -22,7 +22,7 @@ set(CMAKE_AUTORCC ON) # Find the Qt5Core library find_package(Qt5 COMPONENTS Core Gui Network Widgets Xml REQUIRED) list(APPEND QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::Network Qt5::Widgets Qt5::Xml) -if(${Qt5Core_VERSION} VERSION_LESS 5.9) +if(${Qt5Core_VERSION} VERSION_LESS 5.12) message(FATAL_ERROR "Qt version ${Qt5Core_VERSION} found, but version 5.9 or newer is required.") else() message(STATUS "Using Qt5 version ${Qt5Core_VERSION}") diff --git a/gui/app.pro b/gui/app.pro index 1e4307ddd..4d20d0d83 100755 --- a/gui/app.pro +++ b/gui/app.pro @@ -5,6 +5,7 @@ CONFIG += qt CONFIG(debug, debug|release) { CONFIG += console } +CONFIG += c++17 ICON = images/appicon.icns diff --git a/gui/main.cc b/gui/main.cc index 3d8a2614b..87a4a3fdc 100644 --- a/gui/main.cc +++ b/gui/main.cc @@ -29,8 +29,10 @@ //------------------------------------------------------------------------ int main(int argc, char** argv) { -// MIN_QT_VERSION in configure.ac should correspond to the QT_VERSION_CHECK arguments in main.cc and gui/main.cc -#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0)) +// MIN_QT_VERSION in GPSBabel.pro should correspond to the QT_VERSION_CHECK +// arguments in main.cc and gui/main.cc and the version check in +// CMakeLists.txt, gui/CMakeLists.txt. +#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0)) #error this version of Qt is not supported. #endif diff --git a/height.cc b/height.cc index 8f265db02..eb62846f4 100644 --- a/height.cc +++ b/height.cc @@ -32,15 +32,6 @@ #if FILTERS_ENABLED -// Until c++17 we have to define odr-used constexpr static data members at namespace scope. -#if __cplusplus < 201703L -constexpr double HeightFilter::geoid_grid_deg; -constexpr double HeightFilter::geoid_scale; -constexpr int HeightFilter::geoid_row; -constexpr int HeightFilter::geoid_col; -constexpr int8_t HeightFilter::geoid_delta[geoid_row][geoid_col]; -#endif - double HeightFilter::bilinear(double x1, double y1, double x2, double y2, double x, double y, double z11, double z12, double z21, double z22) { if (y1 == y2 && x1 == x2) { diff --git a/igc.cc b/igc.cc index 1375f6c47..fd860c3e4 100644 --- a/igc.cc +++ b/igc.cc @@ -29,6 +29,7 @@ #include // for strcmp, strlen, strtok, strcat, strchr, strcpy, strncat #include // for gmtime, ctime #include // for reverse_iterator, operator==, prev, next +#include // for optional #include // for QByteArray #include // for QList<>::const_iterator @@ -40,7 +41,6 @@ #include "cet_util.h" // for cet_convert_init #include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfputs, gbfgetstr, gbfile #include "src/core/datetime.h" // for DateTime -#include "src/core/optional.h" // for optional static gbfile* file_in, *file_out; @@ -815,8 +815,8 @@ static int correlate_tracks(const route_head* pres_track, const route_head* gnss */ static double interpolate_alt(const route_head* track, time_t time) { - static gpsbabel_optional::optional prev_wpt; - static gpsbabel_optional::optional curr_wpt; + static std::optional prev_wpt; + static std::optional curr_wpt; int time_diff; // Start search at the beginning of the track @@ -825,32 +825,32 @@ static double interpolate_alt(const route_head* track, time_t time) curr_wpt = track->waypoint_list.cbegin(); } // Find the track points either side of the requested time - while ((track->waypoint_list.cend() != curr_wpt.value()) && - ((*curr_wpt.value())->GetCreationTime().toTime_t() < time)) { - prev_wpt = curr_wpt.value(); - curr_wpt = std::next(prev_wpt.value()); + while ((track->waypoint_list.cend() != *curr_wpt) && + ((**curr_wpt)->GetCreationTime().toTime_t() < time)) { + prev_wpt = *curr_wpt; + curr_wpt = std::next(*prev_wpt); } - if (track->waypoint_list.cend() == curr_wpt.value()) { + if (track->waypoint_list.cend() == *curr_wpt) { // Requested time later than all track points, we can't interpolate return unknown_alt; } - if (track->waypoint_list.cbegin() == curr_wpt.value()) { - if ((*curr_wpt.value())->GetCreationTime().toTime_t() == time) { + if (track->waypoint_list.cbegin() == *curr_wpt) { + if ((**curr_wpt)->GetCreationTime().toTime_t() == time) { // First point's creation time is an exact match so use it's altitude - return (*curr_wpt.value())->altitude; + return (**curr_wpt)->altitude; } else { // Requested time is prior to any track points, we can't interpolate return unknown_alt; } } // Interpolate - if (0 == (time_diff = (*curr_wpt.value())->GetCreationTime().toTime_t() - (*prev_wpt.value())->GetCreationTime().toTime_t())) { + if (0 == (time_diff = (**curr_wpt)->GetCreationTime().toTime_t() - (**prev_wpt)->GetCreationTime().toTime_t())) { // Avoid divide by zero - return (*curr_wpt.value())->altitude; + return (**curr_wpt)->altitude; } - double alt_diff = (*curr_wpt.value())->altitude - (*prev_wpt.value())->altitude; - return (*prev_wpt.value())->altitude + (alt_diff / time_diff) * (time - (*prev_wpt.value())->GetCreationTime().toTime_t()); + double alt_diff = (**curr_wpt)->altitude - (**prev_wpt)->altitude; + return (**prev_wpt)->altitude + (alt_diff / time_diff) * (time - (**prev_wpt)->GetCreationTime().toTime_t()); } /* diff --git a/igo8.cc b/igo8.cc index 111f7bd1a..505654bf5 100644 --- a/igo8.cc +++ b/igo8.cc @@ -128,17 +128,17 @@ static QVector igo8_options = { // Sanity check static void igo8_check_type_sizes() { - if (sizeof(igo8_point) != 12) { + if constexpr (sizeof(igo8_point) != 12) { fatal(MYNAME ": igo8_point is %ld bytes instead of the required 12.\n", (long) sizeof(igo8_point)); } - if (sizeof(igo8_information_block) != 12) { + if constexpr (sizeof(igo8_information_block) != 12) { fatal(MYNAME ": igo8_information_block is %ld bytes instead of the required 12.\n", (long) sizeof(igo8_information_block)); } - if (sizeof(igo8_id_block) != 20) { + if constexpr (sizeof(igo8_id_block) != 20) { fatal(MYNAME ": igo8_id_block is %ld bytes instead of the required 20.\n", (long) sizeof(igo8_id_block)); } diff --git a/interpolate.cc b/interpolate.cc index ae1df8ed0..ad1232e79 100644 --- a/interpolate.cc +++ b/interpolate.cc @@ -22,6 +22,7 @@ #include // for INT_MAX #include // for abs, ceil, isfinite, round #include // for abs, atoi, strtod +#include // for optional #include // for QString #include // for qAsConst, QAddConst<>::Type @@ -31,7 +32,6 @@ #include "grtcirc.h" // for linepart, RAD, gcdist, radtomiles #include "src/core/datetime.h" // for DateTime #include "src/core/logging.h" // for Fatal -#include "src/core/optional.h" // for optional #if FILTERS_ENABLED @@ -79,12 +79,12 @@ void InterpolateFilter::process() if (first) { first = false; } else { - gpsbabel_optional::optional timespan; + std::optional timespan; if (wpt->creation_time.isValid() && time1.isValid()) { timespan = wpt->creation_time.toMSecsSinceEpoch() - time1.toMSecsSinceEpoch(); } - gpsbabel_optional::optional altspan; + std::optional altspan; if (altitude1 != unknown_alt && wpt->altitude != unknown_alt) { altspan = wpt->altitude - altitude1; } @@ -96,7 +96,7 @@ void InterpolateFilter::process() fatal(FatalMsg() << MYNAME ": points must have valid times to interpolate by time!"); } // interpolate even if time is running backwards. - npts = std::abs(timespan.value()) / max_time_step; + npts = std::abs(*timespan) / max_time_step; } else if (opt_dist != nullptr) { double distspan = radtomiles(gcdist(RAD(lat1), RAD(lon1), @@ -122,7 +122,7 @@ void InterpolateFilter::process() wpt_new->description = QString(); if (timespan.has_value()) { wpt_new->SetCreationTime(0, time1.toMSecsSinceEpoch() + - round(frac * timespan.value())); + round(frac * *timespan)); } else { wpt_new->creation_time = gpsbabel::DateTime(); } @@ -132,7 +132,7 @@ void InterpolateFilter::process() &wpt_new->latitude, &wpt_new->longitude); if (altspan.has_value()) { - wpt_new->altitude = altitude1 + (frac * altspan.value()); + wpt_new->altitude = altitude1 + (frac * *altspan); } else { wpt_new->altitude = unknown_alt; } diff --git a/interpolate.h b/interpolate.h index c3ba39add..e2590228e 100644 --- a/interpolate.h +++ b/interpolate.h @@ -22,12 +22,13 @@ #ifndef INTERPOLATE_H_INCLUDED_ #define INTERPOLATE_H_INCLUDED_ +#include // for optional + #include // for QVector #include // for qint64 #include "defs.h" // for ARG_NOMINMAX, arglist_t, ARGTYPE_BEGIN_EXCL, ARG... #include "filter.h" // for Filter -#include "src/core/optional.h" // for optional #if FILTERS_ENABLED diff --git a/kml.cc b/kml.cc index 102869893..07435c090 100644 --- a/kml.cc +++ b/kml.cc @@ -25,6 +25,7 @@ #include // for sscanf, printf #include // for atoi, atol, atof #include // for strcmp +#include // for optional #include // for tuple, make_tuple, tie #include // for QByteArray @@ -49,7 +50,6 @@ #include "src/core/datetime.h" // for DateTime #include "src/core/file.h" // for File #include "src/core/logging.h" // for Warning, Fatal -#include "src/core/optional.h" // for optional #include "src/core/xmlstreamwriter.h" // for XmlStreamWriter #include "src/core/xmltag.h" // for xml_findfirst, xml_tag, fs_xml, xml_attribute, xml_findnext #include "units.h" // for fmt_setunits, fmt_speed, fmt_altitude, fmt_distance, units_aviation, units_metric, units_nautical, units_statute diff --git a/lowranceusr.cc b/lowranceusr.cc index ff602d0ae..247f23a7f 100644 --- a/lowranceusr.cc +++ b/lowranceusr.cc @@ -118,33 +118,6 @@ extern WaypointList* global_waypoint_list; #define MYNAME "Lowrance USR" -// Until c++17 we have to define odr-used constexpr static data members at namespace scope. -#if __cplusplus < 201703L -constexpr int LowranceusrFormat::DEF_ICON; -constexpr int LowranceusrFormat::X_1_ICON; -constexpr const char* LowranceusrFormat::DISABLED_CACHE_TXT; -// MSVC 2015 will error with C2373 if the array length isn't explicitly included. -#if !defined(_MSC_VER) || (_MSC_VER >= 1910) /* !MSVC or MSVC 2017 or newer */ -constexpr LowranceusrFormat::lowranceusr_icon_mapping_t LowranceusrFormat::lowranceusr_icon_value_table[]; -#else -constexpr LowranceusrFormat::lowranceusr_icon_mapping_t LowranceusrFormat::lowranceusr_icon_value_table[134]; -#endif -constexpr int LowranceusrFormat::DEF_USR4_ICON; -constexpr int LowranceusrFormat::DEF_USR4_COLOR; -// MSVC 2015 will error with C2373 if the array length isn't explicitly included. -#if !defined(_MSC_VER) || (_MSC_VER >= 1910) /* !MSVC or MSVC 2017 or newer */ -constexpr LowranceusrFormat::lowranceusr4_icon_mapping_t LowranceusrFormat::lowranceusr4_icon_value_table[]; -#else -constexpr LowranceusrFormat::lowranceusr4_icon_mapping_t LowranceusrFormat::lowranceusr4_icon_value_table[22]; -#endif -constexpr int LowranceusrFormat::MAXUSRSTRINGSIZE; -constexpr double LowranceusrFormat::SEMIMINOR; -constexpr double LowranceusrFormat::DEGREESTORADIANS; -constexpr int LowranceusrFormat::MAX_TRAIL_POINTS; -constexpr double LowranceusrFormat::UNKNOWN_USR_ALTITUDE; -constexpr time_t LowranceusrFormat::base_time_secs; -#endif - /* below couple of functions mostly borrowed from raymarine.c */ /* make waypoint shortnames unique */ diff --git a/lowranceusr.h b/lowranceusr.h index 6ac4e66d0..a4bf4621e 100644 --- a/lowranceusr.h +++ b/lowranceusr.h @@ -193,12 +193,7 @@ private: static constexpr int X_1_ICON = 10003; static constexpr const char* DISABLED_CACHE_TXT = "Disabled Cache"; -// MSVC 2015 will error with C2373 if the array length isn't explicitly included. -#if !defined(_MSC_VER) || (_MSC_VER >= 1910) /* !MSVC or MSVC 2017 or newer */ static constexpr lowranceusr_icon_mapping_t lowranceusr_icon_value_table[] = { -#else - static constexpr lowranceusr_icon_mapping_t lowranceusr_icon_value_table[134] = { -#endif /* Taken from iFinder 1.8 */ @@ -361,12 +356,7 @@ private: static constexpr int DEF_USR4_ICON = 2; static constexpr int DEF_USR4_COLOR = 0; -// MSVC 2015 will error with C2373 if the array length isn't explicitly included. -#if !defined(_MSC_VER) || (_MSC_VER >= 1910) /* !MSVC or MSVC 2017 or newer */ static constexpr lowranceusr4_icon_mapping_t lowranceusr4_icon_value_table[] = { -#else - static constexpr lowranceusr4_icon_mapping_t lowranceusr4_icon_value_table[22] = { -#endif /* USR GPX Symbol COLOR1 COLOR2 COLOR3 COLOR4 COLOR5 COLOR6 COLOR7 HOOK2 Displays */ diff --git a/main.cc b/main.cc index 5dd24e5c7..6de61fc2f 100644 --- a/main.cc +++ b/main.cc @@ -645,11 +645,17 @@ main(int argc, char* argv[]) int rc = 0; const char* prog_name = argv[0]; /* may not match QCoreApplication::arguments().at(0)! */ -// MIN_QT_VERSION in configure.ac should correspond to the QT_VERSION_CHECK arguments in main.cc and gui/main.cc -#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0)) +// MIN_QT_VERSION in GPSBabel.pro should correspond to the QT_VERSION_CHECK +// arguments in main.cc and gui/main.cc and the version check in +// CMakeLists.txt, gui/CMakeLists.txt. +#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0)) #error This version of Qt is not supported. #endif +#if defined(_MSC_VER) && (_MSC_VER < 1910) /* MSVC 2015 or earlier */ +#error MSVC 2015 and earlier are not supported. Please use MSVC 2017 or MSVC 2019. +#endif + #ifdef DEBUG_LOCALE printf("Initial locale: %s\n",setlocale(LC_ALL, NULL)); #endif diff --git a/mkicondoc/mkicondoc.pro b/mkicondoc/mkicondoc.pro index 6374e908d..24a31236d 100644 --- a/mkicondoc/mkicondoc.pro +++ b/mkicondoc/mkicondoc.pro @@ -2,7 +2,7 @@ QT -= gui CONFIG += console CONFIG -= app_bundle -CONFIG += c++14 +CONFIG += c++17 TEMPLATE = app diff --git a/route.cc b/route.cc index 36470f4ee..6beddea05 100644 --- a/route.cc +++ b/route.cc @@ -21,6 +21,7 @@ #include // for nullptr_t #include // for sort #include +#include // for optional, operator>, operator< #include // for QDateTime #include // for QList<>::iterator @@ -31,7 +32,6 @@ #include "grtcirc.h" // for RAD, gcdist, heading_true_degrees, radtometers #include "session.h" // for curr_session, session_t (ptr only) #include "src/core/datetime.h" // for DateTime -#include "src/core/optional.h" // for optional, operator>, operator< RouteList* global_route_list; diff --git a/skytraq.cc b/skytraq.cc index 9e92ddc06..20811648d 100644 --- a/skytraq.cc +++ b/skytraq.cc @@ -785,7 +785,7 @@ process_data_item(struct read_state* pst, const item_frame* pitem, int len) case 0xc: /* POI item (same structure as full) */ poi = 1; - /* fallthrough */ + [[fallthrough]]; case 0x2: /* Multi HZ item */ if (len < MULTI_HZ_ITEM_LEN) { @@ -822,7 +822,7 @@ process_data_item(struct read_state* pst, const item_frame* pitem, int len) case 0x6: /* POI item (same structure as full) */ poi = 1; - /* fallthrough */ + [[fallthrough]]; case 0x4: /* full item */ if (len < FULL_ITEM_LEN) { diff --git a/src/core/optional.h b/src/core/deprecated/optional.h similarity index 100% rename from src/core/optional.h rename to src/core/deprecated/optional.h diff --git a/util.cc b/util.cc index 96390bdae..387b0057e 100644 --- a/util.cc +++ b/util.cc @@ -501,7 +501,7 @@ str_match(const char* str, const char* match) return 0; /* incomplete escape sequence */ } /* pass-through next character */ - /* fallthrough */ + [[fallthrough]]; default: if (*m != *s) { @@ -632,7 +632,7 @@ le_read64(void* dest, const void* src) char* cdest = (char*) dest; const char* csrc = (const char*) src; - if (i_am_little_endian) { + if constexpr (i_am_little_endian) { memcpy(dest, src, 8); } else { int i; diff --git a/xcsv.cc b/xcsv.cc index 771fc16d9..98aa71ca9 100644 --- a/xcsv.cc +++ b/xcsv.cc @@ -30,6 +30,7 @@ #include // for atof, atoi, strtod #include // for strlen, strncmp, strcmp, memset #include // for gmtime, localtime, time_t, mktime, strftime +#include // for optional #include // for QByteArray #include // for QChar @@ -56,7 +57,6 @@ #include "session.h" // for session_t #include "src/core/datetime.h" // for DateTime #include "src/core/logging.h" // for FatalMsg -#include "src/core/optional.h" // for optional #include "src/core/textstream.h" // for TextStream #include "strptime.h" // for strptime #include "xcsv.h" @@ -879,10 +879,10 @@ XcsvFormat::read() // If XT_LAT_DIR(XT_LON_DIR) was an input field, and the latitude(longitude) is positive, // assume the latitude(longitude) was the absolute value and take the sign from XT_LAT_DIR(XT_LON_DIR). - if (parse_data.lat_dir_positive.has_value() && !parse_data.lat_dir_positive.value() && (wpt_tmp->latitude > 0.0)) { + if (parse_data.lat_dir_positive.has_value() && !(*parse_data.lat_dir_positive) && (wpt_tmp->latitude > 0.0)) { wpt_tmp->latitude = -wpt_tmp->latitude; } - if (parse_data.lon_dir_positive.has_value() && !parse_data.lon_dir_positive.value() && (wpt_tmp->longitude > 0.0)) { + if (parse_data.lon_dir_positive.has_value() && !(*parse_data.lon_dir_positive) && (wpt_tmp->longitude > 0.0)) { wpt_tmp->longitude = -wpt_tmp->longitude; } diff --git a/xcsv.h b/xcsv.h index f4c6ddc3f..2b43010ae 100644 --- a/xcsv.h +++ b/xcsv.h @@ -22,6 +22,7 @@ #define XCSV_H_INCLUDED_ #include +#include // for optional #include // for move #include // for QByteArray @@ -36,7 +37,6 @@ #include "format.h" #include "garmin_fs.h" #include "src/core/datetime.h" // for DateTime -#include "src/core/optional.h" // for optional #include "src/core/textstream.h" // for TextStream #if CSVFMTS_ENABLED @@ -235,10 +235,10 @@ public: gpsdata_type datatype{unknown_gpsdata}; /* SHORTLEN from style file */ - gpsbabel_optional::optional shortlen; + std::optional shortlen; /* SHORTWHITE from style file */ - gpsbabel_optional::optional whitespace_ok; + std::optional whitespace_ok; private: /* Types */ @@ -346,8 +346,8 @@ private: double utm_zone{0}; char utm_zonec{'N'}; UrlLink* link_{nullptr}; - gpsbabel_optional::optional lat_dir_positive; - gpsbabel_optional::optional lon_dir_positive; + std::optional lat_dir_positive; + std::optional lon_dir_positive; }; /* Constants */ -- 2.30.2